package weapons;

import graphics.MaxGraphics;


import java.awt.Color;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;

import main.Game;

import ship.Ship;
import structure.SObject;
import util.LinAlg;
import util.Point;

public abstract class Mine extends Weapon {
	protected int range;
	protected boolean exploded;
	protected Color color;

	private boolean armed;
	private Point target;

	public Mine(Ship s) {
		super(s);
		target = new Point(Game.game.getTarget());
		vel = LinAlg.scale( LinAlg.unitVectorBetween(cords, target), -WeaponConstants.MINE_SPEED);
		this.target = Game.game.getTarget();
	}


	public void draw(MaxGraphics mg) {
		mg.setColor(color);
		mg.drawRect(getX(), getY(), 5, 5);
	}

	public void update() {
		if(cords.distance(target) < 4 && ! armed) {
			armed = true;
			vel = new Point(0, 0);
		}
		super.update();
	}
	
	public void collide(SObject o) {
		if(armed) {
			if(o instanceof Ship) {
				explode();
			}
		}
	}
	
	public abstract void explode();

	public Shape[] getShape() {
		Shape[] s = { new Ellipse2D.Double(getX() - (range / 2), getY() - (range/2), range, range) };
		return s;
	}

}
